lib.use(['element','form'], function () {
    var form = layui.form;
    var formForm = layui.Form('formForm');
    var reqUrl="";
     form.verify({
         paramKey: function(value, item){
            if(!value){
                 return '参数名不能为空';
            }
        }
       ,paramValue: function(value, item){
             if(!value){
                 return '参数值不能为空';
             }
         }
    });
    form.on('submit(formSubmitFilter)', function (data) {
        var param = formForm.getData();
        common.ajax.post(reqUrl, param, function (resp) {
            common.util.alert('操作成功', function () {
                location.href = 'configList.html';
            })
        })
        return false;
    });


    function loadFormData() {
        var id = common.util.getParam('id');
        if (!id) {
            common.util.error('id错误');
            return;
        }
        common.ajax.get('/sys/config/info/'+id, {}, function (resp) {
            formForm.setData(resp.config);
        });
    }
    (function () {
        if(common.util.getParam('id')){
            //修改
            loadFormData();
            reqUrl="/sys/config/update";
            $("#paramKey").addClass("layui-disabled");
            $("#paramKey").attr("disabled",true);

        }else{
            //新增
            reqUrl="/sys/config/save"
        }
    })();
});
